﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace SerializationHelper
{
    public sealed class SerColOperate : SerTool, ISerColHelper
    {
        public SerColOperate(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            _path = path;
        }
        #region ISerializationCollectionHelper 成员
        public void SerializationCollection<T>(IList<T> collection, SerColType type)
        {
            switch (type)
            {
                case SerColType.Binary:
                    SerializationCollectionToBinary<T>(collection);
                    break;
                case SerColType.XML:
                    SerializationCollectionToXML<T>(collection);
                    break;
            }
        }
        public IList<T> DeSerializationCollection<T>(SerColType type) where T : class
        {
            IList<T> _collection = null;
            switch (type)
            {
                case SerColType.Binary:
                    _collection = DeSerializationBinaryToCollection<T>();
                    break;
                case SerColType.XML:
                    _collection = DeSerializationXMLToCollection<T>();
                    break;
            }
            return _collection;
        }
        #endregion
    }
}
